<template>
  <div class="comment">
    <!-- 头部导航结构 -->
    <van-nav-bar
      title="我的评论"
      left-arrow
      @click-left="$router.back()"
      @click-right="$router.push({ path: '/' })"
    >
    </van-nav-bar>
    <!-- 2.o 评论列表 -->
    <div class="commentList">
      <div class="item" v-for="item in commentList" :key="item.id">
        <p class="date">{{ item.create_date | formdata }}</p>
        <!-- 有引用 -->
        <div class="parent" v-if="item.parent">
          <p class="parent_nickname">回复: {{ item.parent.user.nickname }}</p>
          <p class="parent_comContent">{{ item.parent.content }}</p>
        </div>
        <p class="comment">{{ item.content }}</p>
        <p class="article">
          <router-link class="article_link" :to="`/article/${item.post.id}`">
            原文:{{ item.post.title }}
          </router-link>
        </p>
      </div>
    </div>
    <!-- 3.0 空列表 -->
    <van-empty v-if="commentList.length === 0" description="空空如野" />
  </div>
</template>

<script>
// 💥 用本地服务器的测试账号：10010  密码：123  测试，里面有10条评论数据
import { getUserComments } from "../apis/user";
export default {
  data() {
    return {
      commentList: [],
    };
  },
  async created() {
    const res = await getUserComments();
    // console.log(res);
    this.commentList = res.data.data;
    console.log(this.commentList);
  },
};
</script>

<style lang="less" scoped>
.commentList {
  font-size: 14px;
  .item {
    padding: 10px;
    border-bottom: 1px solid #ddd;
    p {
      margin: 10px 0;
    }
    .date {
      color: #999;
      font-size: 13px;
    }
    .parent {
      background-color: #e4e4e4;
      color: #666;
      font-size: 12px;
      padding: 5px;
    }
    .article {
      font-size: 13px;
      color: #999;
      display: flex;
      .article_link {
        color: inherit;
        width: 90%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }
}
</style>